package com.tgy.admin.controller;

import cn.hutool.core.date.DateUtil;
import com.tgy.result.GraceJSONResult;
import com.tgy.util.email.EmailResource;
import com.tgy.util.email.EmailUtils;
import com.tgy.util.systeminfo.SystemHardwareInfoUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author tianguiyin
 * @version 1.0
 * @date 2022/7/29 14:47
 */
@Validated
@Api(value = "系统信息控制器", tags = {"系统信息管理"})
@RestController
@RequestMapping("/admin/systemInfo")
public class SystemHardwareInfoController {

    @Resource
    private EmailResource emailResource;

    @ApiOperation("获取系统信息")
    @GetMapping("/getSystemInfo")
    public GraceJSONResult getInfo() throws Exception {
        SystemHardwareInfoUtils systemHardwareInfo = new SystemHardwareInfoUtils();
        systemHardwareInfo.copyTo();
        systemHardwareInfo.setTime(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        return GraceJSONResult.ok(systemHardwareInfo);
    }


    @ApiOperation("发送邮件")
    @GetMapping("/sendEmail")
    public GraceJSONResult sendEmail(String email,String content) throws Exception {
        try {
            EmailUtils.sendMail(emailResource.getSender(),emailResource.getAuth(),email,"测试",content);
            return GraceJSONResult.ok();
        }catch (Exception e){
            return GraceJSONResult.error();
        }
    }

}
